package io.cici.worker.actor;

import io.cici.common.request.ServerQueryInstanceStatusRequest;
import io.cici.common.request.ServerScheduleJobRequest;
import io.cici.common.request.ServerStopTaskInstanceRequest;
import io.cici.common.response.AskResponse;
import io.cici.remote.framework.actor.Actor;
import io.cici.remote.framework.actor.Handler;
import lombok.extern.slf4j.Slf4j;

import static io.cici.common.RemoteConstant.*;

/**
 * Worker节点Actor，接受服务器请求
 *
 * @author tjq
 * @since 2020/3/24
 */
@Slf4j
@Actor(path = WORKER_PATH)
public class WorkerActor {

    private final TaskTrackerActor taskTrackerActor;


    public WorkerActor(TaskTrackerActor taskTrackerActor) {
        this.taskTrackerActor = taskTrackerActor;
    }


    @Handler(path = WTT_HANDLER_RUN_JOB)
    public void onReceiveServerScheduleJobReq(ServerScheduleJobRequest req) {
        taskTrackerActor.onReceiveServerScheduleJobReq(req);
    }

    @Handler(path = WTT_HANDLER_STOP_INSTANCE)
    public void onReceiveServerStopInstanceReq(ServerStopTaskInstanceRequest req) {
        taskTrackerActor.onReceiveServerStopInstanceReq(req);
    }

    @Handler(path = WTT_HANDLER_QUERY_INSTANCE_STATUS)
    public AskResponse onReceiveServerQueryInstanceStatusReq(ServerQueryInstanceStatusRequest req) {
        return taskTrackerActor.onReceiveServerQueryInstanceStatusReq(req);
    }
}
